Import-Module oh-my-posh
# oh-my-posh init pwsh --config $env:POSH_THEMES_PATH\\montys.omp.json | Invoke-Expression
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$env:POSH_THEMES_PATH = 'C:\Users\123456\AppData\Local\Programs\oh-my-posh\themes'
# 主题的字体需要安装， 否则带图标的都会显示为乱码
Set-PoshPrompt -Theme montys
# 依赖插件 z  https://www.powershellgallery.com/packages/z/1.1.14
Set-Alias -Name j -Value z
# 默认的 control + l 仅清空当前屏幕， 还能向上滚动查看历史记录
# 新增的 control + k 清空所有
Set-PSReadLineKeyHandler -Chord Ctrl+k -ScriptBlock {
    [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
    [Microsoft.PowerShell.PSConsoleReadLine]::Insert('cls')
    [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
}
# 查找历史命令
function showHistory() {
    param(
        [string] $filterStr
    )
    if ($filterStr) {
        Get-Content (Get-PSReadlineOption).HistorySavePath |  Select-String "$filterStr"
    }
    else {
        Get-Content (Get-PSReadlineOption).HistorySavePath
    }
    
}
# history 保存的文件路径
function showHistoryPath() {
    (Get-PSReadlineOption).HistorySavePath
}

# 显示端口信息
function port(
   
) {
    param(
        [string] $port
    )
    netstat -ano | findstr :$port

}
# 根据查到的进程id 杀掉占用端口
function killPort(
    
) {
    param(
        [string] $killPid
    )
    taskkill /PID $killPid /F
}

function tps() {
    j "rp_tps"
}

function desk() {
    j "rp_desktop_app"
}

function calc() {
    j "tps-calc"
}
function package {
    # 切换到目标目录
    desk

    # 检查 desk 命令是否成功
    if ($?) {
        # 执行 npm run package
        npm run package
    }
    else {
        Write-Host "Failed to change directory with desk."
    }
}
function nginx {
    param (
        [string]$command  # 默认命令
    )
    # # 载入 Windows Forms 程序集
    Add-Type -AssemblyName System.Windows.Forms
    


    # 指定 Nginx 可执行文件和配置文件的完整路径
    $nginxPath = "C:\Program Files\nginx-1.26.2"
 
    cd $nginxPath


    switch ($command) {
        "start" { 
            Start-Process "./nginx.exe"
        }
        "stop" {
            Invoke-Expression "./nginx.exe -s stop"
        }
        "reload" {
            Invoke-Expression "./nginx.exe -s reload" 
        }
        "test" {
            Invoke-Expression "./nginx.exe -t"
        }
        Default {
            [System.Windows.Forms.MessageBox]::Show("default", "456")
            Start-Process "./nginx.exe"
        }
    }

}